# from https://cmake.org/Wiki/CMake:How_To_Find_Libraries

find_package(PkgConfig REQUIRED)
if(PKG_CONFIG_FOUND)

  pkg_search_module(MSMPI  REQUIRED IMPORTED_TARGET msmpi)

  include (FindPackageHandleStandardArgs)
  find_package_handle_standard_args (MSMPI
    REQUIRED_VARS MSMPI_FOUND MSMPI_INCLUDE_DIRS MSMPI_LIBRARIES
    VERSION_VAR MSMPI_VERSION
    )            

  if(NOT TARGET MSMPI::MSMPI)
    add_library(MSMPI::MSMPI ALIAS PkgConfig::MSMPI)
  endif()

  mark_as_advanced(MSMPI_INCLUDE_DIRS MSMPI_LIBRARIES MSMPI_VERSION_MAJOR MSMPI_VERSION_MINOR MSMPI_VERSION_PATCH VERSION_VAR MSMPI_VERSION)
endif()